#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->model = new QStringListModel;
    QStringList cityList;
    cityList<< "北京" << "成都";

    this->model->setStringList(cityList);
    ui->listView->setModel(this->model);

    model2 = new QStandardItemModel();
    QStandardItem *Item = new QStandardItem();
    Item->setCheckable( true );
    Item->setCheckState( Qt::Checked );
    Item->setData("哈哈", Qt::DisplayRole);
    model2->setItem( 0, Item );
    ui->listView_2->setModel( model2 );
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    model->insertRow(model->rowCount());
    auto index = model->index(model->rowCount() - 1, 0);
    model->setData(index, "new Item", Qt::DisplayRole);
    ui->listView->setCurrentIndex(index);
}

void Widget::on_pushButton_3_clicked()
{
    // 获取选中的checkbox 需要遍历
    model2->item(0, 0);
}
